package com.baiyun.test;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class MyJFrame extends JFrame implements ActionListener {
    JButton jtb1 = new JButton("点我啊");
    JButton jtb2 = new JButton("你敢点我吗");

    public MyJFrame() {
        this.setLayout(null);
        //设置长宽高
        this.setSize(603, 680);
        //设置标题
        this.setTitle("拼图单机版 v1.0");
        //将界面置顶
        this.setAlwaysOnTop(true);
        //界面居中
        this.setLocationRelativeTo(null);

        //创建一个按钮
        jtb1.setBounds(0, 0, 100, 50);
        jtb1.setIcon(new ImageIcon("image/login/登录按钮.png"));
//        jtb1.addActionListener(this);

        jtb2.setBounds(100, 0, 100, 50);
//        jtb2.addActionListener(this);

        this.getContentPane().add(jtb1);
        this.getContentPane().add(jtb2);
        //点X后让界面消失
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //保证界面不消失
        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {

        //获取调用的按钮
        Object source = e.getSource();
        if (source == jtb1) {
            jtb1.setSize(200, 200);
        } else if (source == jtb2) {
            Random r = new Random();
            jtb2.setLocation(r.nextInt(500), r.nextInt(500));
        }
    }
}
